<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>登录界面</title>
  <link rel="stylesheet" href="./css/style.css">
  <link rel="stylesheet" href="./css/body.css">
</head>

<body>
  <div class="container">
    <section id="content">
      <form>
        <h1>账号登录</h1>
        </h1>
        <div>
          <i class="close">X</i>
          <input type="text" placeholder="手机号" id="username">
        </div>
        <div>
          <i class="close">X</i>
          <input type="password" placeholder="密码" id="password">
        </div>
        <div>
          <input type="submit" value="登录" class="btn btn-primary" id="js-btn-login">
          <a href="../03-pwdBaseCode/index.html">忘记密码?</a>
          <a href="../02-regbaseCode/reg.html">注册账号</a>
        </div>
      </form>
    </section>
  </div>
  <!-- <script src="../jq/jQuery.js"></script> -->
  <script src="./axios.js"></script>
  <script src="./log.js"></script>
  <script>


    // 地址统一配置
    axios.defaults.baseURL = 'http://124.223.14.236:3001/api'
    let btn = document.querySelector('#js-btn-login')
    btn.addEventListener('click', async function () {
      //  获取用户账号密码
      const username = document.querySelector('#username').value
      const password = document.querySelector('#password').value
      //  调用接口, 传递参数, 发送请求


      const { data:{data} } = await axios.post('/user/login', {
        password,
        username
      }
      )
      console.log(data)
      localStorage.setItem('token', data.token)

    })
    //   $.ajax({
    //     method: 'POST',  //  请求方式
    //     url: 'http://124.223.14.236:3001/api/user/login', //  接口地址
    //     //  将数据发送给服务器
    //     data: {
    //       username,
    //       password,
    //     },
    //     success: function (res) {
    //       // console.log(res.data.token)
    //       localStorage.setItem('token', res.data.token)
    //     }
    //   })

    // })

  </script>
</body>

</html>